const { promisify } = require('util');

const download = promisify(require('download-git-repo'));
const open = require('open');

const { vueRope } = require('../config/repo-config')
const { commandSpawn } = require('../utils/terminal');

const createProjectAction = async (project) =>{

  console.log("正在创建中")
  console.log("请稍等~~~~~~~~~~")

//    克隆模板
   await download(vueRope, project, {clone: true});
//npm install
  const command = process.platform === 'win32' ? 'npm.cmd' : 'npm';
  await commandSpawn(command, ['install'], { cwd: `./${project}` })

//npm run serve
   commandSpawn(command, ['run','serve'], { cwd: `./${project}` })

//打开阅览器
 open('http://localhost:8080/')
}

module.exports = {
    createProjectAction
}